//
//  I_Upload.m
//  FullShareTop
//
//  Created by lqq on 2017/4/14.
//  Copyright © 2017年 FSB. All rights reserved.
//

#import "I_APPManager.h"



@implementation I_APPManager


/**
 上传设备信息
 */
+ (NetworkTask *)uploadDeviceInfo
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    BOOL success = [defaults boolForKey:@"UpLoadDeviceInfoSuccess"];
    if (success) {
        return nil;
    }
    return [NET POST:@"/gym-api/app/1.0.0/device" parameters:nil criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        [defaults setBool:YES forKey:@"UpLoadDeviceInfoSuccess"];
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
    }];
}




/**
 上传推送token
 */
+ (NetworkTask *)upLoadPushToken
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    BOOL success = [defaults boolForKey:@"UpLoadPushTokenSuccess"];
    if (success) {
        return nil;
    }
    NSString *pushToken = [[NSUserDefaults standardUserDefaults] objectForKey:kPushTokenKey];
    return [NET POST:@"/gym-api/app/1.0.0/umengtoken" parameters:@{@"umengToken":SAFE_NIL_STRING(pushToken)} criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        [defaults setBool:YES forKey:@"UpLoadPushTokenSuccess"];
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
    }];
}


/**
 检查APP更新
 */
+ (NetworkTask *)checkAPPUpdateSuccess:(void(^)(NSDictionary *response))successBlock failure:(ErrorBlock)failureBlock
{

    return [NET POST:@"/gym-api/app/1.0.0/resentVersion" parameters:nil criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        NSDictionary *result = [resultObject safeObjectForKey:@"data"];
        if (successBlock) {
            successBlock(result);
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }

    }];
    return nil;
}

/**
 获取广告
 */
+ (NetworkTask *)requestAdvertOnSuccess:(void(^)(NSMutableArray *advertList))successBlock failure:(ErrorBlock)failureBlock
{
    return [NET POST:@"/gym-coach-api/system/1.0.0/getAdvertising" parameters:@{@"column":@"-1",@"fence":@"-1"} criticalValue:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull resultObject) {
        
        if (successBlock) {
            NSMutableArray *advertList = [M_Advert arrayOfModelsFromDictionaries:[resultObject safeObjectForKey:@"data"] error:nil];
            successBlock(advertList);
        }
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        if (failureBlock) {
            failureBlock(error);
        }
//        if (successBlock) {
//            NSMutableArray *advertList = [NSMutableArray array];
//            M_Advert *advert = [[M_Advert alloc] init];
//            advert.advertPic = @"http://dynamic-image.yesky.com/740x-/uploadImages/2014/289/01/IGS09651F94M.jpg";
//            advert.jumpType = JumpType_H5;
//            advert.jumpTarget = @"http://www.baidu.com";
//            advert.delayTime = 5000;
//            advert.expireTime = [NSString stringWithFormat:@"%lld",(long long)([[NSDate date] timeIntervalSince1970] * 1000 + 1000)];
//            [advertList addObject:advert];
//            successBlock(advertList);
//        }
        
    }];
}


@end
